package com.gzzq.util;

//import com.alibaba.fastjson.JSON;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

public class ResponseUtil
{
  private static final String STATUTS = "status";
  private static final String MSG = "msg";
  private static final String ERRORCODE = "errorCode";
  private static final String RESULT = "result";
  private static final String TOTAL = "total";
  private static final String ROWS = "rows";

  public static void validateResult(HttpServletResponse response, boolean status)
  {
    response.reset();
    response.setContentType("text/html;charset=UTF-8");
    try {
      response.getWriter().print(status);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

/*  public static void jsonResult(HttpServletResponse response, Object result)
  {
    response.reset();
    response.setContentType("application/json;charset=UTF-8");
    try {
      String json = JSON.toJSONString(result);
      response.getWriter().print(json);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }*/

  public static Map<String, Object> tableResult(long total, List<?> dataList)
  {
    Map map = new HashMap();
    map.put("total", Long.valueOf(total));
    map.put("rows", dataList);
    return map;
  }

  public static Map<String, Object> trueResult()
  {
    Map map = new HashMap();
    map.put("status", Boolean.TRUE);
    return map;
  }

  public static Map<String, Object> falseResult()
  {
    Map map = new HashMap();
    map.put("status", Boolean.FALSE);
    return map;
  }

  public static Map<String, Object> trueTipResult(String msg)
  {
    Map map = new HashMap();
    map.put("status", Boolean.TRUE);
    map.put("msg", msg);
    return map;
  }

  public static Map<String, Object> falseTipResult(String msg)
  {
    Map map = new HashMap();
    map.put("status", Boolean.FALSE);
    map.put("msg", msg);
    return map;
  }

  public static Map<String, Object> trueBizResult(Object result)
  {
    Map map = new HashMap();
    map.put("status", Boolean.TRUE);
    map.put("result", result);
    return map;
  }

  public static Map<String, Object> falseBizResult(Object result)
  {
    Map map = new HashMap();
    map.put("status", Boolean.FALSE);
    map.put("result", result);
    return map;
  }

  public static Map<String, Object> trueBizResult(Object result, String msg)
  {
    Map map = new HashMap();
    map.put("status", Boolean.TRUE);
    map.put("msg", msg);
    map.put("result", result);
    return map;
  }

  public static Map<String, Object> falseBizResult(Object result, String msg)
  {
    Map map = new HashMap();
    map.put("status", Boolean.TRUE);
    map.put("msg", msg);
    map.put("result", result);
    return map;
  }

  public static Map<String, Object> trueBizResult(Object result, String msg, String errorCode)
  {
    Map map = new HashMap();
    map.put("status", Boolean.TRUE);
    map.put("msg", msg);
    map.put("errorCode", errorCode);
    map.put("result", result);
    return map;
  }

  public static Map<String, Object> falseBizResult(Object result, String msg, String errorCode)
  {
    Map map = new HashMap();
    map.put("status", Boolean.FALSE);
    map.put("msg", msg);
    map.put("errorCode", errorCode);
    map.put("result", result);
    return map;
  }
}
